/*
 * Copyright (C) 2004, Velocityme Partnership
 * NotificationMechanismBean.java
 *
 * Created on 15 June 2004, 08:51
 */

package com.velocityme.entity;

import javax.ejb.*;
import javax.naming.*;
import java.rmi.*;
import javax.rmi.*;
import com.velocityme.interfaces.*;
import com.velocityme.interfaces.ServiceUnavailableException;

/**
 *
 * @author  Robert
 * @ejb.bean
 *           type="CMP"
 *           cmp-version="2.x"
 *           name="NotificationMechanism"
 *           jndi-name="ejb/Permission"
 *           view-type="local"
 * @ejb.transaction type="Required"
 *
 * @ejb.value-object match="*"
 *
 * @ejb.persistence table-name="notificationmechanism"
 *
 * @ejb.util generate="physical"
 *
 * @ejb.finder signature="java.util.Collection findAll()"
 *              query="SELECT OBJECT(o) FROM NotificationMechanism o"
 *
 * @ejb.finder signature="com.velocityme.interfaces.NotificationMechanism findByName(java.lang.String name)"
 *              query="SELECT OBJECT(o) FROM NotificationMechanism o WHERE o.name = ?1"
 *
 * @jboss.persistence create-table="true"
 *                    remove-table="false"
 */
public abstract class NotificationMechanismBean implements EntityBean {
    
    public static final int UNSUPPORTED = 0;
    public static final int EMAIL = 1;
    public static final int SMS = 2;
    public static final int FAX = 3;
    public static final int NUM_TYPES = 4;

    /**
    * Context set by container
    */
    private javax.ejb.EntityContext m_entityContext;

    public void setEntityContext(javax.ejb.EntityContext entityContext) {
        m_entityContext = entityContext;
    }

    public void unsetEntityContext() {
        m_entityContext = null;
    }
  
    /** @ejb.create-method */
    public NotificationMechanismPK ejbCreate(java.lang.Integer p_type) throws javax.ejb.CreateException {
        setNotificationMechanismId(p_type);
        // EJB 2.0 spec says return null for CMP ejbCreate methods.
        return null;
    }

    public void ejbPostCreate(java.lang.Integer p_type) throws javax.ejb.CreateException {
        // CMR relations must be set in ejbPostCreate
        String name;
        switch(p_type.intValue()) {
            case UNSUPPORTED: name = "Unsupported"; break;
            case EMAIL:       name = "Email"; break;
            case SMS:         name = "Sms"; break;
            case FAX:         name = "Fax"; break;
            default:          name = "Unknown Mechanism"; break;
        }
        setName(name);
    }
    
    /**
     *  This gets a local object from a remote object.
     *  @ejb.interface-method view-type="remote"
     */
    public PermissionLocal getLocal() {
        return (PermissionLocal)m_entityContext.getEJBLocalObject();
    }
    
    /** @ejb.interface-method view-type="local" */
    public abstract com.velocityme.valueobjects.NotificationMechanismValue getNotificationMechanismValue();

    //=======================================================================
    //
    //                   ATTRIBUTES
    //
    //=======================================================================
      
    /**
     * @ejb.persistence column-name="notificationMechanismId"
     * @ejb.interface-method view-type="local"
     * @ejb.pk-field 
     */
    public abstract java.lang.Integer getNotificationMechanismId();
    public abstract void setNotificationMechanismId(java.lang.Integer notificationMechanismId);
    
    /**
     * @ejb.persistence column-name="name"
     * @ejb.interface-method view-type="local"
     */
    public abstract java.lang.String getName();
    public abstract void setName(java.lang.String name);
    
    //=======================================================================
    //
    //                   RELATIONSHIPS
    //
    //=======================================================================
    
    //=======================================================================
    //
    //                   MANAGEMENT METHODS
    //
    //=======================================================================
    
}
